const { validateToken } = require('../helpers/user');
exports.auth = (ctx, next) => {
    const token = ctx.get('Authorization');
    if (token) {
        try {
            const res = validateToken(token);
            if (res) { // 校验通过
                next();
            } else {
                ctx.body = {
                    code: 0,
                    msg: '权限不足'
                }
            }
        } catch (e) {
            ctx.body = {
                code: 0,
                msg: '权限不足'
            }
        }
    }
}